home *** CD-ROM | disk | FTP | other *** search
/ Aminet 52 / Aminet 52 (2002)(GTI - Schatztruhe)[!][Dec 2002].iso / Aminet / util / moni / Scout-src.lha / source / startup.c < prev    next >
C/C++ Source or Header  |  2002-09-16  |  4KB  |  107 lines

  1. /**
  2.  * Scout - The Amiga System Monitor
  3.  *
  4.  *------------------------------------------------------------------
  5.  *
  6.  * This program is free software; you can redistribute it and/or modify
  7.  * it under the terms of the GNU General Public License as published by
  8.  * the Free Software Foundation; either version 2 of the License, or
  9.  * any later version.
  10.  *
  11.  * This program is distributed in the hope that it will be useful,
  12.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  * GNU General Public License for more details.
  15.  *
  16.  * You should have received a copy of the GNU General Public License
  17.  * along with this program; if not, write to the Free Software
  18.  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19.  *
  20.  * You must not use this source code to gain profit of any kind!
  21.  *
  22.  *------------------------------------------------------------------
  23.  *
  24.  * @author Andreas Gelhausen
  25.  * @author Richard Körber <rkoerber@gmx.de>
  26.  */
  27.  
  28. #include "system_headers.h"
  29.  
  30. #define EXECBASE        (*(struct ExecBase **)4)
  31. #define aprintf         Printf
  32.  
  33. extern struct ExecBase    *SysBase;
  34. struct DosLibrary *DOSBase;
  35. struct IntuitionBase *IntuitionBase;
  36. struct Library *UtilityBase;
  37. struct Library *IconBase;
  38.  
  39. struct Args opts;
  40. UBYTE __aligned stack[] = "$STACK: 16384\n";
  41.  
  42. ULONG __saveds startup(void)
  43. {
  44.     ULONG rc = RETURN_OK;
  45.     struct Process *me;
  46.     struct WBStartup *wbmsg = NULL;
  47.  
  48.     SysBase = EXECBASE;
  49.  
  50.     me = (struct Process *)FindTask(NULL);
  51.  
  52.     if (!me->pr_CLI) {
  53.         WaitPort(&me->pr_MsgPort);
  54.         wbmsg = (struct WBStartup *)GetMsg(&me->pr_MsgPort);
  55.     }
  56.  
  57.     if (DOSBase = (struct DosLibrary *)OpenLibrary(DOSNAME, 37)) {
  58.         if (IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library", 37)) {
  59.             if (UtilityBase = OpenLibrary(UTILITYNAME, 37)) {
  60.                 struct SmartArgs sa;
  61.  
  62.                 IconBase = OpenLibrary(ICONNAME, 37);
  63.  
  64.                 memset(&sa, 0x00, sizeof(struct SmartArgs));
  65.                 sa.sa_Template = TEMPLATE;
  66.                 sa.sa_Parameter = (LONG *)&opts;
  67.                 sa.sa_FileParameter = -1;
  68.                 sa.sa_Window = "CON:20/20/400/100/Scout/AUTO/CLOSE/WAIT";
  69.  
  70.                 if (SmartReadArgs(wbmsg, &sa) == 0) {
  71.                     if (opts.ToolPri != NULL && (*opts.ToolPri < -128 || *opts.ToolPri > 127)) {
  72.                         FPrintf(Output(), "ToolPri is not in range (-128..127).\n");
  73.                     } else if (opts.CpuDisplay != NULL && (*opts.CpuDisplay < 0 || *opts.CpuDisplay > 2)) {
  74.                         FPrintf(Output(), "CpuDisplay is not in range (0..2).\n");
  75.                     } else {
  76.                         LONG oldtaskpri = 0;
  77.  
  78.                         if (opts.ToolPri) oldtaskpri = SetTaskPri((struct Task *)me, *opts.ToolPri);
  79.  
  80.                         // Call the main program
  81.                         rc = scout_main();
  82.  
  83.                         // Reset program priority if necessary
  84.                         if (opts.ToolPri) SetTaskPri((struct Task *)me, (LONG)oldtaskpri);
  85.                     }
  86.                 }
  87.                 SmartFreeArgs(&sa);
  88.  
  89.                 if (IconBase) CloseLibrary(IconBase);
  90.                 CloseLibrary(UtilityBase);
  91.             }
  92.  
  93.             CloseLibrary((struct Library *)IntuitionBase);
  94.         }
  95.  
  96.         CloseLibrary((struct Library *)DOSBase);
  97.     }
  98.  
  99.     if (wbmsg) ReplyMsg((struct Message *)wbmsg);
  100.  
  101.     return rc;
  102. }
  103.  
  104. void __stdargs _XCEXIT (long mist)
  105. {
  106. }
  107.